home *** CD-ROM | disk | FTP | other *** search
- Rem BlockHead
- Rem by Andrew Howat
- Rem Use the arrow keys to
- Rem control the "Head" and
- Rem try to clear as many
- Rem bricks as possible
-
- Rem See the bottom of
- Rem this program for some
- Rem ideas for changes.
-
- paddleWidth = 40
- paddleSpeed = 2
-
- blockRows = 2
- blockCols = 8
-
- blockWidth = 40
- blockHeight = 24
-
- ballSize = 6
- ballHalfSize = 3
-
- ballExtraSpeed = 0
-
- numLives = 3
- score = 0
-
- minTime = 15
-
- Dim blocks(blockCols,blockRows)
-
- rem -------------------
- rem Program Start
- rem -------------------
- Cls
-
- Background "BrkOut"
-
- bounceSnd = LoadSound("BOUNCE")
- headHitSnd = LoadSound("HEADCONK")
- fallThruSnd = LoadSound("GAMESHOW")
- row1HitSnd = LoadSound("BONKUP")
- row2HitSnd = LoadSound("BONK")
- startLevelSound$ = "VICTORY"
- gameOverSound$ = "GAMOVER2"
- clearedLevelSound$ = "CROWD"
-
- screenWidth = 320
- screenHeight = 240
-
- Gosub SetupBlocks
-
- Gosub SetupPaddle
-
- Gosub SetupBall
-
- Rem Fill bottom of screen to be used for lives and score.
- Color 3 'Black
- FillRect 0,222 To 320,240
-
- Gosub ShowLivesAndScore
-
- lastTime = Timer()
- RunGame = TRUE
- While RunGame = TRUE
-
- Gosub ProcessInput
-
- Gosub MoveBall
-
- Gosub ShowPaddleAndBall
-
- Rem Enforce a limiting speed for fast machines
- while timer() < lastTime + minTime
- wend
- lastTime = timer()
-
- Wend
-
- Color 3 'Black
- FillRect 100,75 To 220,120
- TextColor 6
- Position 16, 5
- Print "Game Over"
- Position 15, 6
- Print "Score = " score
-
- Rem Then play Game Over sound
- Sound(gameOverSound$)
- Rem Delay to let sound finish!
- Sleep 30
-
- End
-
- rem -------------------
- SetupBlocks:
- rem -------------------
-
- tmpFrame = 0
- blockCount = 0
-
- for row = 1 to blockRows
- for col = 1 to blockCols
-
- blocks(col,row) = LoadSprite("Blocks")
-
- If row = 1 Then
- Rem Pick one of the eyes
- tmpFrame = random(2,4)
- Else
- If row = 2 Then
- Rem Pick one of the noses
- tmpFrame = random(0,1)
- Else
- Rem Pick one of the mouths
- tmpFrame = random(5,6)
- EndIf
- EndIf
-
- SetSprite blocks(col,row) To (col-1)*blockWidth, (row-1)*blockHeight
- SetSprite blocks(col,row) Frame tmpFrame
-
- Rem Keep track of how many blocks there are.
- blockCount = blockCount + 1
-
- Next col
- Next row
-
- Rem Play the sound that we're ready
- Rem to start a new level!
- Sound(startLevelSound$)
-
- Return
-
- rem -------------------
- SetupPaddle:
- rem -------------------
- paddle = LoadSprite("BrkOut")
-
- Rem Set starting position of paddle
- paddleX = 100
- paddleY = 190
- SetSprite paddle To paddleX,paddleY
- SetSprite paddle Frame 2
-
- hitPaddle = 0
-
- Return
-
- rem -------------------
- SetupBall:
- rem -------------------
- ball = LoadSprite("BrkOut")
-
- Gosub RestartBall
-
- Return
-
- rem -------------------
- RestartBall:
- rem -------------------
-
- Rem Position ball in middle of paddle
- ballX = paddleX + (paddleWidth/2)
- ballY = paddleY
-
- Rem Set the initial speed of the ball
- ballSpeedX = 1
- ballSpeedY = -1
-
- SetSprite ball To ballX,ballY
- SetSprite ball Frame 0
-
- Rem Pause a moment to let player
- Rem get ready
- HideSprite ball
- Sleep 10
- ShowSprite ball
-
- Return
-
- rem -------------------
- ShowPaddleAndBall:
- rem -------------------
-
- If hitPaddle = 0 Then
- SetSprite paddle Frame 2
- Else
- hitPaddle = hitPaddle - 1
- EndIf
-
- SetSprite paddle To paddleX,paddleY
-
- SetSprite ball To ballX-ballHalfSize, ballY-ballHalfSize
-
- Return
-
- rem -------------------
- ProcessInput:
- rem -------------------
-
- If KeyDown("CURRIGHT") Then
- paddleX = paddleX + paddleSpeed
-
- If paddleX > (screenWidth-paddleWidth) Then
- paddleX = screenWidth-paddleWidth
- EndIf
-
- Else
- If KeyDown("CURLEFT") Then
- paddleX = paddleX - paddleSpeed
-
- If paddleX < 0 Then
- paddleX = 0
- EndIf
-
- EndIf
- EndIf
-
- If KeyDown("Q") THEN
- RunGame = 0
- EndIf
-
- Return
-
- rem -------------------
- MoveBall:
- rem -------------------
-
- prevBallX = ballX
- prevBallY = ballY
-
- ballX = ballX + ballSpeedX
- ballY = ballY + ballSpeedY
-
- Rem Has the ball hit the right edge
- Rem of the screen?
- If ballX >= (screenWidth-ballHalfSize) Then
- PlaySound(bounceSnd)
- ballX = screenWidth-ballHalfSize-1
- ballSpeedX = -ballSpeedX
- Else
- Rem Has the ball hit the left edge?
- If ballX < ballHalfSize Then
- PlaySound(bounceSnd)
- ballX = ballHalfSize
- ballSpeedX = -ballSpeedX
- EndIf
- Endif
-
- Rem Has the ball gone pass the top
- Rem of the screen?
- If ballY <= ballHalfSize Then
- PlaySound(bounceSnd)
- ballY = ballHalfSize
- ballSpeedY = -ballSpeedY
- Else
- Rem Has the ball gone pass the bottom
- Rem of the screen
- If ballY > screenHeight Then
- PlaySound(fallThruSnd)
- Rem Decrease the number of lives
- numLives = numLives - 1
-
- Gosub ShowLivesAndScore
-
- Rem Do we have any lives left
- If numLives > 0 Then
- Rem Restart ball
- Sleep 10
- Gosub RestartBall
- Else
- Rem Set flag indicating game is over.
- RunGame = 0
- EndIf
- EndIf
- EndIf
-
- Rem Check to see if the ball has hit
- Rem anything.
- Gosub CheckCollisions
-
- Return
-
-
- rem -------------------
- CheckCollisions:
- rem -------------------
-
- rem Has the ball hit a block?
-
- rem Based on the ball position, which
- rem block do we need to test.
- testCol = Int(ballX/blockWidth)+1
- testRow = Int(ballY/blockHeight)+1
-
- Rem Do we need to check collisions
- Rem with blocks.
- If testRow <= blockRows Then
-
- Rem Is there a block at the test position?
- If blocks(testCol,testRow) >= 0 Then
- Gosub HandleBlockCollision
- EndIf
-
- Rem Are all the blocks gone?
- If blockCount = 0 Then
-
- Sound(clearedLevelSound$)
-
- Gosub SetupBlocks
-
- Gosub RestartBall
-
- Rem Speed up for next round.
- ballExtraSpeed = ballExtraSpeed + 1
- paddleSpeed = paddleSpeed + 1
-
- EndIf
-
- Else
-
- Rem Has the paddle been hit?
-
- Rem Is the ball within paddle range?
- If ballY >= paddleY-ballHalfSize Then
- rem If ballY <= paddleY+ballHalfSize Then
-
- Rem Is the ball between the paddle limits
- If ballX >= paddleX Then
- If ballX <= (paddleX+paddleWidth) Then
- Gosub HandlePaddleCollision
- EndIf
- EndIf
-
- rem EndIf
- EndIf
-
- EndIf
-
- Return
-
-
- rem -------------------
- HandlePaddleCollision:
- rem -------------------
-
- Rem Is the ball too far down to
- Rem allow it to bounce up?
- If ballY >= paddleY+ballSize Then
- ballSpeedX = -ballSpeedX
- Else
-
- Rem Which section of the paddle
- Rem did the ball hit?
- If ballX < (paddleX+10) Then
- ballSpeedX = -2
- ballSpeedY = -1
- Else
- If ballX < (paddleX+20) Then
- ballSpeedX = -1
- ballSpeedY = -2
- Else
- If ballX < (paddleX+30) Then
- ballSpeedX = 1
- ballSpeedY = -2
- Else
- ballSpeedX = 2
- ballSpeedY = -1
- EndIf
- EndIf
- EndIf
-
- Rem Add in any extra speed.
- If ballSpeedX >= 0 Then
- ballSpeedX = ballSpeedX + ballExtraSpeed
- Else
- ballSpeedX = ballSpeedX - ballExtraSpeed
- EndIf
-
- ballSpeedY = ballSpeedY - ballExtraSpeed
- EndIf
-
- Rem Set paddle face to "ouch" frame
- SetSprite paddle Frame 1
- PlaySound(headHitSnd)
-
- Rem Set the count for how long the
- Rem "ouch" frame should show.
- hitPaddle = 30
-
- Return
-
- rem -------------------
- HandleBlockCollision:
- rem -------------------
-
- Rem testRow and testCol contain the position
- Rem of the block that has been hit.
-
- Rem What is the position of the block hit?
- blockX = (testCol-1) * blockWidth
- blockY = (testRow-1) * blockHeight
-
- If prevBallX >= blockX Then
- If prevBallX < (blockX + blockWidth) Then
- Rem Change Y direction
- ballSpeedY = -ballSpeedY
- EndIf
- EndIf
-
- If prevBallY >= blockY Then
- If prevBallY < (blockY + blockHeight) Then
- Rem Change X direction
- ballSpeedX = -ballSpeedX
- EndIf
- EndIf
-
- Rem Play a different sound depending
- Rem on which row was hit
- If testRow = 1 Then
- PlaySound(row1HitSnd)
- Else
- PlaySound(row2HitSnd)
- EndIf
-
- Rem Remove the block from the screen
- HideSprite blocks(testCol,testRow)
- FreeSprite blocks(testCol,testRow)
-
- Rem Set the block as not existing
- Rem in the array
- blocks(testCol,testRow) = -1
-
- Rem Decrease the number of blocks left.
- blockCount = blockCount - 1
-
- Rem Increase player score
- score = score + (blockRows-testRow)*5
-
- Gosub ShowLivesAndScore
-
- Return
-
- rem -------------------
- ShowLivesAndScore:
- rem -------------------
-
- TextColor 6
- Position 1,14
- Print "Lives = " numLives;
-
- Position 28,14
- Print "Score = " score;
-
- Return
-
- rem -------------------
-
-
- Rem ============================
- Rem SUGGESTIONS TO MAKE IT YOUR WAY!
- Rem
- Rem - Add a High Score List.
- Rem (See the project hints for an example)
- Rem - Give an extra life if you
- Rem complete a level
- Rem - Change the graphics for the
- Rem blocks and/or the background
- Rem with each new level.
- Rem - Make advanced levels that
- Rem include bonus point bricks
-
-
-
-
-